package com.wu.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
import java.util.*;

public class DateUtil {private static final Logger LOGGER = LoggerFactory.getLogger(DateUtil.class);

    /**
     * 获取时间当前日期
     * @return LocalDate
     */
    public static LocalDate getLocalDate(){
        return LocalDate.now();
    }

    /**
     * 获取当前时间
     * @return LocalDateTime
     */
    public static LocalDateTime getLocalDateTime(){
        return LocalDateTime.now();
    }

    /**
     * 获取当前时间毫秒数
     * @return Long
     */
    public static Long getDateTimeStamp(){
        return LocalDateTime.now().atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
    }

    /**
     * 获取Date类型当前时间
     * @return Date
     */
    public static Date getDateTime(){
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zonedDateTime = LocalDateTime.now().atZone(zoneId);
        Date dateTime = Date.from(zonedDateTime.toInstant());
        return dateTime;
    }

    /**
     *获取Date类型当前日期
     * @return Date
     */
    public static Date getDate(){
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zonedDateTime = LocalDate.now().atStartOfDay(zoneId);
        Date date = Date.from(zonedDateTime.toInstant());
        return date;
    }
    /**
     * 利用DateTimeFormatter类自带的格式定义日期时间
     * @param date
     * @param formatter
     * @return
     */
    public static LocalDate formatter(String date,DateTimeFormatter formatter){
        return LocalDate.parse(date,formatter);
    }

    /**
     * 自定义格式日期时间
     * DateTimeFormatter.ofPattern第二个参数也可以指定地域，有需要可以自己封装
     * @param date
     * @param formatter
     * @return
     */
    public static LocalDate formatter(String date,String formatter){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(formatter);
        return LocalDate.parse(date,dateTimeFormatter);
    }
}